define([
  '../common/ReminderPanel'
], function (ReminderPanel) {
  let reminder = new ReminderPanel()                            //提示框
  let satelliteMap, digitalMap, suzhouDigitalMap, suzhouSatelliteMap, beijingDigitalMap, beijingSatelliteMap
  let imageryLayerCollection = viewer.scene.imageryLayers       //图层集合

  /*
    图层切换管理入口
   */
  return function (viewer) {

    //如果图层中已包含则置顶， 否则创建并置顶。 防止添加相同图层
    $('#loadSatelliteMap').click(function () {
      if (imageryLayerCollection.contains(satelliteMap)) {
        imageryLayerCollection.raiseToTop(satelliteMap)
      } else {
        satelliteMapProvider = Cesium.createTileMapServiceImageryProvider({
          url: '../data/SatelliteMap',
          credit: '卫星地图'
        })
        satelliteMap = imageryLayerCollection.addImageryProvider(satelliteMapProvider)
        reminder.show('加载卫星地图')
      }
    })

    $('#loadDigitalMap').click(function () {
      //解决南北极无法正常显示
      imageryLayerCollection.removeAll();
      if (imageryLayerCollection.contains(digitalMap)) {
        imageryLayerCollection.raiseToTop(digitalMap)
      } else {
        digitalMapProvider = Cesium.createTileMapServiceImageryProvider({
          url: '../data/DigitalMap',
          credit: '电子地图'
        })
        digitalMap = imageryLayerCollection.addImageryProvider(digitalMapProvider)
        reminder.show('加载电子地图')
      }
    })

    $('#loadSuzhouDigitalMap').click(function () {
      //镜头改变，直接传入笛卡尔坐标值
      viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(120.5, 31.3, 3000.0)
      })
      if (imageryLayerCollection.contains(suzhouDigitalMap)) {
        imageryLayerCollection.raiseToTop(suzhouDigitalMap)
      } else {
        suzhouDigitalMapProvider = Cesium.createTileMapServiceImageryProvider({
          url: '../data/SuZhouDigital',
          credit: '苏州电子地图'
        })
        suzhouDigitalMap = imageryLayerCollection.addImageryProvider(suzhouDigitalMapProvider)
        reminder.show('加载苏州电子地图')
      }
    })

    $('#loadSuzhouSatelliteMap').click(function () {
      viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(120.5, 31.3, 3000.0)
      })
      if (imageryLayerCollection.contains(suzhouSatelliteMap)) {
        imageryLayerCollection.raiseToTop(suzhouSatelliteMap)
      } else {
        suzhouSatelliteMapProvider = Cesium.createTileMapServiceImageryProvider({
          url: '../data/SuZhouSatellite',
          credit: '苏州卫星地图'
        })
        suzhouSatelliteMap = imageryLayerCollection.addImageryProvider(suzhouSatelliteMapProvider)
        reminder.show('加载苏州卫星地图')
      }
    })

    $('#loadBeijingSatelliteMap').click(function () {
      viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(116.3, 39.9, 3000.0)
      })
      if (imageryLayerCollection.contains(beijingSatelliteMap)) {
        imageryLayerCollection.raiseToTop(beijingSatelliteMap)
      } else {
        beijingSatelliteMapProvider = Cesium.createTileMapServiceImageryProvider({
          url: '../data/BeiJingSatellite',
          credit: '北京卫星地图'
        })
        beijingSatelliteMap = imageryLayerCollection.addImageryProvider(beijingSatelliteMapProvider)
        reminder.show('加载北京卫星地图')
      }
    })

    $('#loadBeijingDigitalMap').click(function () {
      viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(116.3, 39.9, 3000.0)
      })
      if (imageryLayerCollection.contains(beijingDigitalMap)) {
        imageryLayerCollection.raiseToTop(beijingDigitalMap)
      } else {
        beijingDigitalMapProvider = Cesium.createTileMapServiceImageryProvider({
          url: '../data/BeiJingDigital',
          credit: '北京电子地图'
        })
        beijingDigitalMap = imageryLayerCollection.addImageryProvider(beijingDigitalMapProvider)
        reminder.show('加载北京电子地图')
      }
    })

    //清除图层
    $('#clearAllMap').click(function () {
      imageryLayerCollection.removeAll()
      satelliteMapProvider = Cesium.createTileMapServiceImageryProvider({
        url: '../data/SatelliteMap',
        credit: '卫星地图'
      })
      satelliteMap = imageryLayerCollection.addImageryProvider(satelliteMapProvider)
    })
  }
})